package com.guizi.halftimesroom.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.guizi.halftimesroom.R;
import com.guizi.halftimesroom.bean.RecommandSquareBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Alan on 2016/7/20.
 */
public class RecommandSquareView extends LinearLayout {
    private Context mContext;
    private LinearLayout ll_square;

    public RecommandSquareView(Context context) {
        this(context,null);
    }

    public RecommandSquareView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public RecommandSquareView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        this.mContext=context;
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_discover_recommand_square, this);
        ll_square = (LinearLayout) view.findViewById(R.id.ll_square);
    }
    public void setData(List<RecommandSquareBean.DataBean> list){
        for (int i = 0; i <list.size(); i++) {
            if(list.get(i).getCover().contains("http")){
                ImageView imageView = new ImageView(mContext);
                LayoutParams params = new LayoutParams(0, 130,1f);
                params.setMargins(5,5,5,5);
                imageView.setLayoutParams(params);
                Picasso.with(mContext).load(list.get(i).getCover()).into(imageView);
                ll_square.addView(imageView);
            }else{
                TextView textView = new TextView(mContext);
                LayoutParams params = new LayoutParams(0, 130,1f);
                params.setMargins(5,5,5,5);
                textView.setLayoutParams(params);
                textView.setBackgroundColor(getResources().getColor(R.color.pink));
                textView.setGravity(Gravity.CENTER);
                textView.setText(list.get(i).getPlain());
                ll_square.addView(textView);
            }
        }
    }
}
